<template>
	<view class="chart-playlist">
		<!-- 官方榜: official-list -->
		<view class="official-list">
			<view class="list-title">官方榜</view>
			<view class="offical-list-item" @click="toPlaylist(item.id)" v-for="(item, index) of chartsDatas[0]" :key="index">
				<view class="offical-img">
					<image :src="item.coverImgUrl"></image>
					<view class="list-time">{{ item.updateFrequency }}</view>
				</view>
				<view class="official_tracks">
					<view class="tracks-item" v-for="(track, index) of item.tracks" :key="index">
						<text class="index">{{ index + 1 }}</text>
						<text class="song_name text_ellipsis">{{ track.first }} - {{ track.second }}</text>
					</view>
				</view>
			</view>
		</view>
		<!-- 官方榜 -->
		<!-- 其他榜 -->
		<view class="other-list">
			<view class="list-title">其他榜</view>
			<view class="other-list-content">
				<view class="other-list-item" @click="toPlaylist(item.id)" v-for="(item, index) of chartsDatas[1]" :key="index">
					<view class="other-img">
						<image :src="item.coverImgUrl"></image>
						<view class="list-time">{{ item.updateFrequency }}</view>
					</view>
					<view class="other-name text_2line_ellipsis">{{ item.name }}</view>
				</view>
			</view>
		</view>
		<!-- 其他榜 -->
		<BottomBar />
	</view>
</template>

<script>
	import BottomBar from '../index/childComps/BottomBar.vue'
	import { chartPlaylist } from '../../api/index.js'
	export default {
		data() {
			return {
				// 榜单分类数据
				chartsDatas: []
			}
		},
		components: {BottomBar},
		onLoad() {
			this.chartPlaylistFun()
		},
		methods: {
			// 请求排行榜摘要数据
			async chartPlaylistFun() {
				const { data: res } = await chartPlaylist()
				// 进行榜单分类
				const result = [[], []]
				res.list.forEach((v, i) => {
					if (!v.ToplistType) {
						result[1].push(v)
					} else {
						result[0].push(v)
					}
				})
				this.chartsDatas = result
			},
			// 点击去往playlist页面
			toPlaylist(playListId) {
				uni.navigateTo({
					url: '/pages/playlist/playlist?playListId=' + playListId
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.chart-playlist {
		padding: 20rpx;
		.list-title {
			font-weight: bold;
			font-size: 37rpx;
			margin-bottom: 20rpx;
		}
		.list-time {
			position: absolute;
			right: 10rpx;
			top: 10rpx;
			color: #ffffff;
			font-size: 25rpx;
			background-color: rgba(0, 0, 0, .1);
			padding: 0 10rpx;
			border-radius: 20rpx;
		}
		.official-list {
			.offical-list-item {
				display: flex;
				margin: 10rpx 0;
				.offical-img {
					position: relative;
					margin-right: 20rpx;
					image {
						width: 230rpx;
						height: 230rpx;
						min-width: 230rpx;
						border-radius: 20rpx;
						box-shadow: 12rpx -12rpx 5rpx rgba(0, 0, 0, .1);
            background: url('@/static/images/song/default.png') no-repeat center center;
            background-size: cover;
					}
				}
				.official_tracks {
					display: flex;
					flex-direction: column;
					justify-content: space-around;
					.tracks-item {
						display: flex;
						align-items: center;
						width: 460rpx;
						.song_name {
							margin-left: 10rpx;
						}
					}
				}
			}
		}
		.other-list {
			margin-bottom: 100rpx;
			.other-list-content {
				display: flex;
				flex-wrap: wrap;
				.other-list-item {
					display: flex;
					flex-direction: column;
					align-items: center;
					flex: 1;
					margin: 15rpx 0;
					.other-img {
						width: 200rpx;
						height: 200rpx;
						position: relative;
						image {
							width: 100%;
							height: 100%;
							border-radius: 15rpx;
							box-shadow: 10rpx -10rpx 3rpx rgba(0, 0, 0, .1);
              background: url('@/static/images/song/default.png') no-repeat center center;
              background-size: cover;
						}
					}
					.other-name {
						width: 200rpx;
						margin-top: 10rpx;
						font-size: 28rpx;
						// 允许在单词内换行。
						word-break: break-all;
					}
				}
			}
		}
	}
</style>
